package cn.toleo.activiti.controller;


import cn.toleo.activiti.service.ActService;
import cn.toleo.dto.activiti.ActivitiRequestDto;
import cn.toleo.dto.activiti.ActivitiResultDto;
import cn.toleo.dto.global.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//2018.1.8;toleo;工作流Activit;
@Controller
public class ActivitiController {
    @Autowired
    private ActService actService;

    //springmvc层进入测试
    @RequestMapping(value = "/a",method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult a(@RequestBody ActivitiRequestDto activitiRequestDto)throws  Exception{
        System.out.println("1926#####################################################");
        return  ResponseResult.success();
    }


    //2018.2.13;toleo;01部署流程
    @RequestMapping(value = "/activiti/deploy",method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult create(@RequestBody ActivitiRequestDto activitiRequestDto)throws  Exception{
        ActivitiResultDto activitiResultDto = new ActivitiResultDto();
        actService.deploy(activitiRequestDto.getDeployFile());
        activitiResultDto.setMsg("部署成功");
        //结果
        return  ResponseResult.success(activitiResultDto);

    }

    //2018.2.13;toleo;02启动流程
    @RequestMapping(value ="/activiti/start",method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult start(@RequestBody ActivitiRequestDto activitiRequestDto){
        ActivitiResultDto resultDto = actService.start(activitiRequestDto);
        //结果
        return  ResponseResult.success(resultDto);
    }

    //2018.2.13;toleo;03根据人查看任务
    @RequestMapping(value = "/activiti/query",method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult queryByPerson(@RequestBody ActivitiRequestDto activitiRequestDto){

        List<ActivitiResultDto> activitiResultDto = actService.queryByPerson(activitiRequestDto.getPerson());
        //结果
        return  ResponseResult.success(activitiResultDto);
    }

    //2018.2.13;toleo;04办理userTask
    @RequestMapping(value = "/activiti/action",method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult action(@RequestBody ActivitiRequestDto activitiRequestDto){
        //主干
        ActivitiResultDto resultDto = actService.action(activitiRequestDto);
        resultDto.setMsg("普通任务办理完成,请办理下一步流程");
        //结果
        return  ResponseResult.success(resultDto);
    }

    //2018.3.1;toleo;05办理receiveTask
    @RequestMapping(value = "/activiti/recTask",method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult recTask(@RequestBody ActivitiRequestDto activitiRequestDto){
        ActivitiResultDto activitiResultDto = new ActivitiResultDto();
        //主干
        actService.recTask(activitiRequestDto);
        activitiResultDto.setMsg("短信或者邮件发送完毕,receriTask任务办理完成");
        //结果
        return  ResponseResult.success(activitiResultDto);
    }

    //2018.3.1;toleo;06根据activitiId查询 executionId
    @RequestMapping(value = "/activiti/queryByRec",method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult queryByRec(@RequestBody ActivitiRequestDto activitiRequestDto){
        List<ActivitiResultDto> activitiResultDto = actService.queryByaActivitiId(activitiRequestDto.getRecName());
        //结果
        return  ResponseResult.success(activitiResultDto);
    }




}
